/**
 * Copyright (C) 2008-2012 www.pretty-tools.com
 */

const nsISupports = Components.interfaces.nsISupports;

const wsshIGlobalDialogKeeper = Components.interfaces.wsshIGlobalDialogKeeper;

const wsshGlobalDialogKeeper_CLASS_ID = Components.ID("{D246E379-9CCC-4466-9050-66404D2230CB}");
const wsshGlobalDialogKeeper_CLASS_NAME = "wsshGlobalDialogKeeper";
const wsshGlobalDialogKeeper_CONTRACT_ID = "@pretty-tools.com/wsshGlobalDialogKeeper;1";

var wsshGlobalDialogKeeperFactory = {
    createInstance: function (aOuter, aIID)
    {
        if (aOuter != null)
            throw Components.results.NS_ERROR_NO_AGGREGATION;

        return (new wsshGlobalDialogKeeper()).QueryInterface(aIID);
    }
};

var wsshGlobalDialogKeeperModule = {
    registerSelf: function(aCompMgr, aFileSpec, aLocation, aType)
    {
        aCompMgr = aCompMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar);
        aCompMgr.registerFactoryLocation(wsshGlobalDialogKeeper_CLASS_ID, wsshGlobalDialogKeeper_CLASS_NAME, wsshGlobalDialogKeeper_CONTRACT_ID, aFileSpec, aLocation, aType);
    },

    unregisterSelf: function(aCompMgr, aLocation, aType)
    {
        aCompMgr = aCompMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar);
        aCompMgr.unregisterFactoryLocation(wsshGlobalDialogKeeper_CLASS_ID, aLocation);
    },

    getClassObject: function(aCompMgr, aCID, aIID)
    {
        if (!aIID.equals(Components.interfaces.nsIFactory))
            throw Components.results.NS_ERROR_NOT_IMPLEMENTED;

        if (aCID.equals(wsshGlobalDialogKeeper_CLASS_ID))
            return wsshGlobalDialogKeeperFactory;

        throw Components.results.NS_ERROR_NO_INTERFACE;
    },

    canUnload: function(aCompMgr)
    {
        return true;
    }
};

function NSGetModule(aCompMgr, aFileSpec)
{
    return wsshGlobalDialogKeeperModule;
}

function NSGetFactory(aCID)
{
    if (aCID.equals(wsshGlobalDialogKeeper_CLASS_ID))
        return wsshGlobalDialogKeeperFactory

    throw Components.results.NS_ERROR_FACTORY_NOT_REGISTERED;
}

function wsshGlobalDialogKeeper()
{
    this.wrappedJSObject = this;
    this._theLastSlideShowDialog = null;
}

wsshGlobalDialogKeeper.prototype = {
    // this must match whatever is in chrome.manifest!
    classID: wsshGlobalDialogKeeper_CLASS_ID,

    get theLastSlideShowDialog() { return this._theLastSlideShowDialog; },
    set theLastSlideShowDialog(theLastSlideShowDialog) { this._theLastSlideShowDialog = theLastSlideShowDialog; }
}

wsshGlobalDialogKeeper.prototype.QueryInterface = function(aIID)
{
    if (!aIID.equals(wsshIGlobalDialogKeeper) && !aIID.equals(nsISupports))
        throw Components.results.NS_ERROR_NO_INTERFACE;

    return this;
}
